<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>扫码揽件</title>
<%@ include file="/pages/wx/baseHead.jsp"%>
<!-- #cb60b3 -->
<style type="text/css">
.btn-my { background: #cb60b3; /* Old browsers */ 
background: -moz-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* FF3.6+ */ 
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #cb60b3),color-stop(50%, #ad1283), color-stop(100%, #de47ac) ); /* Chrome,Safari4+ */ 
background : -webkit-linear-gradient( top, #cb60b3 0%,#ad1283 50%, #de47ac 100%); /* Chrome10+,Safari5.1+ */ 
background: -o-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* Opera 11.10+ */ 
background: -ms-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* IE10+ */ 
background: linear-gradient(to bottom, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* W3C */ 
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cb60b3',endColorstr='#de47ac', GradientType=0 ); /* IE6-9 */ }
.btn-my{ width: 100px; height: 100px; -moz-border-radius: 50%; -webkit-border-radius: 50%; border-radius: 50%; }
.btn-my { background: gray; color:#ffffff; }
</style>
<script type="text/javascript">
	
	$(function(){
		$('#search').keydown(function(e)
			{
				if(e.keyCode==13)
				{
					loadOrder();
				}
			});
		initWxSdk();
	});
	
	function initWxSdkOk()
	{
		$("#touchArea")[0].style.background = '#04BE02';
		$("#msg").html('点击扫描条形码/二维码');
		var barcode = '${barcode}';
		if(isNull(barcode))scan();
	}
	
	function scan()
	{
		wx.scanQRCode({
		    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		    success: function (res) {
		    	var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
		    	$("#search").val(result.split(",")[1]);
		    	loadOrder();
			}
		});
	}
	
	function scanExp()
	{
		wx.scanQRCode({
		    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		    success: function (res) {
		    	var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
		    	$("#scanExpNoMsg").html('已扫描，点击重新扫描');
		    	$("#scanExpNoMsgNo").html("单号："+result.split(",")[1]);
		    	$("#expCode").val(result.split(",")[1]);
		    	hide("#step1");
		    	$("#step2")[0].style.display="";
			}
		});
	}
	
	function loadOrder()
	{
		var orderNo = $("#search").val();
		if(hasBlank(orderNo))
		{
			show("#orderEmpty");
			hide("#orderInfo");
			hide("#scanExpOrder");
			$("#errorMsg").html("请输入正确的快递单");
			return;
		}
		if(orderNo == '')
		{
			show("#orderEmpty");
			hide("#orderInfo");
			hide("#scanExpOrder");
			$("#errorMsg").html("请输入条形码");
			return;
		}
		//$("#theform").submit();
		to('${urlBasePath }weixin/user/toExpressLanshou.do?barcode='+orderNo);
	}
	
	
	function setChangePrice()
	{
		var sn = $("#sn").val();
		var weight =$("#changeWeight").val();
		var price = $("#changePrice").val();
		var errorTag = $("#updatePriceErrorDiv");
		if(isNull(weight))
		{
			errorTag.html('请输入重量');
			return;
		}
		if(hasBlank(weight) || isNaN(weight))
		{
			errorTag.html('请输入正确的重量');
			return;
		}
		weight = parseFloat(weight);
		if(weight <= 0)
		{
			errorTag.html('请输入正确的重量');
			return;
		}
		if(weight > 10000)
		{
			errorTag.html('重量请控制在10000以内');
			return;
		}
		
		if(isNull(price))
		{
			errorTag.html('请输入价格');
			return;
		}
		
		if(hasBlank(price) ||isNaN(price))
		{
			errorTag.html('请输入正确的价格');
			return;
		}
		price = parseFloat(price);
		if(price <= 0)
		{
			errorTag.html('请输入正确的价格');
			return;
		}
		if(price > 10000)
		{
			errorTag.html('价格请控制在10000以内');
			return;
		}
		hide('.changePrice');
		confirm('提示','确定要修改价格吗？',function(){
			var url = '${urlBasePath}weixin/user/changePrice.do';
			loading('正在计价');
			$.ajax({
				url:url,
				async:true,
				data:{
					sn:sn,
					price:price,
					weight:weight
				},
				success:function(ret){
					unLoading();
					if(ret.code == '0')
					{
						openToast('计价完成');
						$("#amountDiv1").html(price.toFixed(2));
						$("#amountDiv2").html(price.toFixed(2));
						$("#weightDiv").html(weight);
						
					}else
					{
						openDia('提示',ret.msg);
					}
				},
				error:function(){
					unLoading();
					alert('系统错误');
				}
			});
			
		});
	}
	
	/*揽收*/
	function bindExpCode()
	{
		var sn = $("#sn").val();
		var expcode = $("#expCode").val();
		var priceHtml = $("#amountDiv2").html();
		var price = parseFloat(priceHtml);
		var regs = /^[A-Za-z0-9]+$/;
		if(!regs.test(expcode))
		{
			openDia('提示','请输入正确的快递单号');
			return;
		}
		if(price <= 0)
		{
			openDia('提示','请设置正确的费用');
			return;
		}
		confirm('提示','<font color="red">快递费为：'+priceHtml+'</font>,确定要揽件？',function(){
			var url = '${urlBasePath}weixin/user/bindExpCode.do';
			$.ajax({
				url:url,
				async:true,
				data:{
					sn:sn,
					expcode:expcode
				},
				success:function(ret){
					if(ret.code == '0')
					{
						$("#expcodeFont").html(expcode);
						confirm('提示','揽件成功',
								function(){to('toExpressLanshou.do');},
								function(){$(".confirmwx").find(".weui_btn_confirm_dialog_cancel")[0].style.display='none'}
								)
					}else
					{
						openDia('提示',ret.msg);
					}
				},
				error:function(){
					
				}
			});
			
		});
	}
	
	function setExpNo()
	{
		$("#inputExpNoErrorDiv").html("");
		var expNo = $("#inputExpNo").val();
		var regs = /^[A-Za-z0-9]+$/;
		if(!regs.test(expNo))
		{
			$("#inputExpNoErrorDiv").html("请输入正确的快递单号");
			return;
		}
		$("#scanExpNoMsg").html('已输入,单号'+expNo);
    	$("#expCode").val(expNo);
    	hide('.inputExpressNoCls');
    	show("#commitBtn");
	}
	
	function reScanBarCode()
	{
		show('#scanDiv');
		hide('#orderInfo');
		show('#orderEmpty');
		hide('#step1');
		scan();
	}
</script>

</head>
<body>
<div class="alert alert-info" role="alert" id="scanDiv"
<c:if test="${obj.sn != null }">
		style="display:none;"
	</c:if>
>
	<div class="input-group margin-bottom-sm form-inline has-success">
		<span class="input-group-addon" onclick="scan();"><i class="fa fa-qrcode fa-fw"></i>&nbsp;</span>
	<%-- <form action="${urlBasePath }weixin/user/toExpressLanshou.do" name="theform" id="theform" method="POST"> --%>
	  <input class="form-control col-md-3" type="text" value="${barcode }" name="barcode" id="search" placeholder="请输入条形码" style="height: 46px;z-index: 1;" >
	 <!-- </form>  -->
	  <span class="input-group-addon"><a href="javascript:void(0);" onclick="loadOrder();">
	  	<i class="fa fa-search fa-sm"></i></a>
	  </span>
	  </span>
	</div>
	
		<nav>
		  <ul class="pager" style="padding-top: -10em;">
		  	<button id="touchArea" type="button" class="btn btn-my" onclick="scan();">
		  		<i class="fa fa-qrcode fa-3x voiceCls"></i>
		  	</button>
		  	<div id="msg" style="height: 10px;display: block;padding-top: 10px;">扫描功能暂时无法使用</div>
		  </ul>
		</nav>
	
</div>


	<div class="weui_msg"
	<c:if test="${obj.sn != null }">
		style="display:none;"
	</c:if>
	 id="orderEmpty">
		   <!-- <div class="weui_icon_area"><i class="weui_icon_safe_warn weui_icon_msg"></i></div> -->
		   <div class="weui_text_area">
		       <p class="weui_msg_desc">
		       <p style="color: red" id="errorMsg">
		       		<c:if test="${tip != null }">
		       			${tip}
		       		</c:if>
		       	</p><br>	
		       		请扫描单号或者手动输入单号加载订单信息
		       	</p>
		   </div>
		</div>
	
	
	<c:if test="${obj.sn != null }">
		<input type="hidden" id="sn" value="${obj.sn }">
		<div class="bd" id="orderInfo" style="margin-top: -15px;">
	    <div class="weui_panel weui_panel_access">
	    	<div class="weui_panel_hd">
	        	<%-- <div align="center" style="font-size: 1.2em;color: red;">
	        	
	        		估算费用：<fmt:formatNumber value="${obj.proposedPrice }" pattern="#,##0.00"/></font>元
	        		费用：<font id="amountDiv1"><fmt:formatNumber value="${obj.amount }" pattern="#,##0.00"/></font>元
	        	</div> --%>
	        	<div align="center">
		        	<a style="width: 46%;height: 40px;padding-top: 8px;" class="weui_btn weui_btn_plain_primary weui_btn_mini" href="tel:${obj.fromPhone }">
		        		<i class="fa fa-phone fa-fw"></i>&nbsp; 联系个人
		        	</a>
		        	
		        	<a style="width: 46%;height: 40px;padding-top: 8px;" class="weui_btn weui_btn_plain_primary weui_btn_mini " onclick="show('.changePrice');">
		        		<i class="fa fa-cny fa-fw"></i>&nbsp; 点击计费
		        	</a>
	       	 	</div>
	       	 	
	        </div>
	        <div class="weui_panel_bd">
	            <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg form-inline">
	                <div class="weui_media_bd">
	                    <h4 class="weui_media_title">快递公司：${obj.expCompName }</h4>
	                   <p class="weui_media_desc">
	                    	<i class="fa fa-male fa-fw"></i>物品：${obj.goodsType } <font id="weightDiv">${obj.weight }</font> kg 
	                    	&nbsp;
	                    	<i class="fa fa-cny fa-fw"></i>保价：
	                    	<fmt:formatNumber value="${null == obj.supportValue?0:obj.supportValue }" pattern="#,##0.00"/>元
	                    </p>
	                    <%-- <p class="weui_media_desc"><i class="fa fa-cny fa-fw"></i>估算费用：<fmt:formatNumber value="${obj.proposedPrice }" pattern="#,#00.00"/> 元</p> --%>
	                    <p class="weui_media_desc"><i class="fa fa-cny fa-fw"></i>实际费用：<font id="amountDiv2"><fmt:formatNumber value="${obj.amountExper }" pattern="#,##0.00"/></font> 元</p>
	                    <p class="weui_media_desc"><i class="fa fa-th-list fa-fw"></i>订单号：${obj.sn }</p>
	                    <p class="weui_media_desc"><i class="fa fa-barcode fa-fw"></i>条形码：<font id="barcodeFont">${obj.barCode }</font></p>
	                    <p class="weui_media_desc"><i class="fa fa-reorder fa-fw"></i>快递单：<font id="expcodeFont">${obj.expressNo }</font></p>
	                </div>
	            </a>
	        </div>
	        
	        <div class="weui_panel_hd" style="font-size: 1.2em;">收件人信息</div>
	        <div class="weui_panel_bd">
	            <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg form-inline">
	                <div class="weui_media_bd">
	                    <h4 class="weui_media_title">收件人：${obj.directionName }</h4>
	                    <p class="weui_media_desc"><i class="fa fa-phone fa-fw"></i>电话：${obj.directionPhone }</p>
	                    <p class="weui_media_desc"><i class="fa fa-location-arrow fa-fw"></i>地址：${obj.directionAddress }</p>
	                </div>
	            </a>
	        </div>
	        
	        <div class="weui_panel_hd" style="font-size: 1.2em;">寄件人信息</div>
	        <div class="weui_panel_bd">
	            <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg form-inline">
	                <div class="weui_media_bd">
	                    <h4 class="weui_media_title">寄件人：${obj.fromName }</h4>
	                    <p class="weui_media_desc"><i class="fa fa-phone fa-fw"></i>电话：${obj.fromPhone }</p>
	                    <p class="weui_media_desc"><i class="fa fa-location-arrow fa-fw"></i>地址：${obj.fromAddress }</p>
	                </div>
	            </a>
	        </div>
	    </div>
	</div>

	
	<!-- 弹出修改价格Div -->
	<div class="weui_dialog_confirm changePrice" style="display: none;">
		   <div class="weui_mask"></div>
		   <div class="weui_dialog">
		       <div class="weui_dialog_hd"><strong class="weui_dialog_title1 weui_dialog_confirm_title">请修改重量以及价格</strong></div>
		       <div class="weui_dialog_bd weui_dialog_confirm_bd">
		       		<div class="form-inline">
		       			重量：
		       			<input class="weui_input" type="text"  style="height: 38px;width:40%;
				       		border: 1px solid #04BE02;border-radius:5px;" id="changeWeight"
							placeholder="" value="${obj.weight }" /> 单位：公斤kg
					</div>							
					<div class="form-inline" style="margin-top: 2px;">							
						价格：
			       		<input class="weui_input" type="text"  style="height: 38px;width:40%;padding-top:2px;
				       		border: 1px solid #04BE02;border-radius:5px;" id="changePrice"
							placeholder="" /> 单位：元
		       		</div>
		       		<div id="updatePriceErrorDiv" align="center" style="padding-top:12px;color: red;display: block;">&nbsp;</div>
		       </div>
		       <div class="weui_dialog_ft">
		       	   <a href="javascript:hide('.changePrice');" class="weui_btn_dialog default weui_btn_confirm_dialog_cancel">关闭</a>
		           <a href="javascript:setChangePrice();" class="weui_btn_dialog primary weui_btn_confirm_dialog_ok">确定</a>
		       </div>
		      
		   </div>
	</div>
	<!-- 弹出修改价格Div -->
	
	
	<!-- 弹出手输快递单Div -->
	<div class="weui_dialog_confirm inputExpressNoCls" style="display: none;">
		   <div class="weui_mask"></div>
		   <div class="weui_dialog">
		       <div class="weui_dialog_hd"><strong class="weui_dialog_title1 weui_dialog_confirm_title">请填入快递单号</strong></div>
		       <div class="weui_dialog_bd weui_dialog_confirm_bd">
		       		<div class="form-inline">
		       			<input class="weui_input" type="text"  style="height: 42px;
				       		border: 1px solid #04BE02;border-radius:5px;" id="inputExpNo" maxlength="20" 
							placeholder="请输入快递单号" value="" />
		       		</div>
		       		<div align="center" style="color: red;display: block;padding-top: 5px;" id="inputExpNoErrorDiv">&nbsp;</div>
		       </div>
		       <div class="weui_dialog_ft">
		       	   <a href="javascript:hide('.inputExpressNoCls');" class="weui_btn_dialog default weui_btn_confirm_dialog_cancel">关闭</a>
		           <a href="javascript:setExpNo();" class="weui_btn_dialog primary weui_btn_confirm_dialog_ok">确定</a>
		       </div>
		      
		   </div>
	</div>
	<!-- 弹出修改价格Div -->
	
	<div class="weui_tabbar" id="step1" style="position: fixed;bottom: 0%;left: 0%;">
	    <div class="weui_tabbar_item " onclick="reScanBarCode();" style="background-color: #EFEFF4;">
	        <p class="weui_tabbar_label">
	        	<div style="font-size:1.2em;color:#04BE02 ;padding-top: 5px;" align="center">
	        		<font>重新扫描</font><br>
	        	</div>
	        </p>
	    </div>
	    <div class="weui_bar_item_on" onclick="" id="scanExpNoBtnId" style="width: 50%;padding-top: 1.0em;background-color:#04BE02;">
	        <p class="weui_tabbar_label" onclick="scanExp();" style="line-height: 40px;font-size:1.2em;color: #ffffff">
	        	下一步扫码
	        </p>
	    </div>
	</div>
	
	<div class="weui_tabbar" id="step2" style="position: fixed;bottom: 0%;left: 0%;display: none;">
	    <div class="weui_tabbar_item " onclick="scanExp();" style="background-color: #EFEFF4;">
	        <p class="weui_tabbar_label">
	        	<div style="color: #04BE02;padding-top: 5px;" align="center">
	        		<font id="scanExpNoMsg">点击扫码</font><br>
	        		<font id="scanExpNoMsgNo" color="red"></font>
	        		<input type="hidden" id="expCode">
	        	</div>
	        </p>
	    </div>
	    <div class="weui_bar_item_on" onclick="bindExpCode();" style="width: 50%;padding-top: 1.0em;background-color:#04BE02;">
	        <p class="weui_tabbar_label" style="line-height: 40px;font-size:1.2em;color: #ffffff">
	        	完成
	        </p>
	    </div>
	</div>
	
	<div style="height: 60px;display: block;"></div>
</c:if>

<div class="pop">
    <i class="fa fa-home fa-lg popi"></i>
</div>

<!-- 引入微信样式代码提示工具开始 -->
<%@ include file="/pages/wx/wxClass.jsp"%>
<!-- 引入微信样式代码提示工具结束 -->
<%@ include file="/pages/wx/baseBottom.jsp"%>
</body>
</html>

